# -*- coding: utf-8 -*-
"""
@Time ： 2023/9/15 9:09
@Auth ： y.h
@File ：doc_util.py
@IDE ：PyCharm
@Motto：The sooner you start to code, the longer the program will take. —— Roy Carlson
"""
from pathlib import Path

tree_str = ''
def generate_tree(pathname, n=0):
    global tree_str
    if pathname.is_file():
        tree_str += '    |' * n + '-' * 4 + pathname.name + '\n'
    elif pathname.is_dir():
        tree_str += '    |' * n + '-' * 4 + \
            str(pathname.relative_to(pathname.parent)) + '\\' + '\n'
        for cp in pathname.iterdir():
            generate_tree(cp, n + 1)

if __name__ == '__main__':
    path = 'D:/xxx/xxx/xxx'
    generate_tree(Path(path), 0)
    print(tree_str)
